using System;
using System.Collections;

namespace CoreMobile.cmd
{
    public class VABProtocol : IProtocol
    {


        public static char ELEMENT_SEPARATOR = ',';
        public static char GROUP_SEPARATOR = ';';

        /*
        public string commandSend(IProtocolCommand protocolCommand, IParameter[] parameters)
        {
            if(parameters.Length <= 0) throw new Exception("0-parameters exception");
            string command = "";

            foreach (var parameter in parameters)
            {
                command += this.commandSend(protocolCommand, parameter)
                           + this.group_separator;
            }
            return command;
        }*/

        public string commandSend(SendCommand protocolCommand, IParameter parameter)
        {
            protocolCommand.Parameter = parameter;
            return protocolCommand.asLine()
                    + GROUP_SEPARATOR;
        }

        public ArrayList commandReceive(string multiline)
        {
            ArrayList objects=new ArrayList();
            //MessageBox.Show("r:" + multiline);
            foreach (var line in multiline.Split(GROUP_SEPARATOR))
            {
                if(!string.IsNullOrEmpty(line))
                  objects.Add(VABProtocol.createReceiveCommand(line.Split(ELEMENT_SEPARATOR))
                              .Parameter);
            }



            return objects;
        }

        public static ReceiveCommand createReceiveCommand(string[] parameters)
        {
                /*if (parameters[0] == TurnoDatosCommand.CMD)
                    return new TurnoDatosCommand(parameters);

                if (parameters[0] == AsientoCommand.CMD)
                    return new AsientoCommand(parameters);
                */
                throw new Exception("Command ["+parameters[0]+"] isnt a receive command");
        }
    }
}